﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Quickly.Identity.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quickly.Identity
{
    public sealed class AppUserAccessor(UserManager<AppUser> userManager)
    {
        public async Task<AppUser> GetRequiredUserAsync(HttpContext context)
        {
            var user = await userManager.GetUserAsync(context.User);

            if (user == null)
            {
                throw new InvalidUserException(userManager.GetUserId(context.User));
            }

            return user;
        }
    }
}
